using System.Collections.Generic;
using System.Data.Common;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.OracleClient;
using System.Data.SqlClient;

namespace MINERP.COM.DBHelper {
	/// <summary>The param builder.</summary>
	public static class ParamBuilder {
		/// <summary>The create parameter.</summary>
		/// <param name="parms">The parms.</param>
		/// <param name="dbType">The db type.</param>
		/// <returns></returns>
		public static DbParameter[] CreateParameter(Dictionary<string, object> parms, string dbType) {
			if (parms == null) {
				return null;
			}
			DbParameter[] parameterArray;
			int count = parms.Count;
			int index = 0;
			string str = dbType;
			if (str != null) {
				if (str != "System.Data.OracleClient") {
					if (str == "System.Data.Odbc") {
						parameterArray = new OdbcParameter[count];
						goto Label_0086;
					}
					if (str == "System.Data.OleDb") {
						parameterArray = new OleDbParameter[count];
						goto Label_0086;
					}
					if (str == "System.Data.SqlClient") {
						parameterArray = new SqlParameter[count];
						goto Label_0086;
					}
				}
				else {
					parameterArray = new OracleParameter[count];
					goto Label_0086;
				}
			}
			parameterArray = new SqlParameter[count];
			Label_0086:
			foreach(KeyValuePair<string, object> pair in parms) {
				parameterArray[index] = CreateParameter(dbType, pair.Key, pair.Value);
				index++;
			}
			return parameterArray;
		}
		/// <summary>The create parameter.</summary>
		/// <param name="dbType">The db type.</param>
		/// <param name="fieldName">The field name.</param>
		/// <param name="val">The val.</param>
		/// <returns></returns>
		public static DbParameter CreateParameter(string dbType, string fieldName, object val) {
			switch (dbType) {
				case "System.Data.OracleClient":
					return new OracleParameter(fieldName, val);
				case "System.Data.Odbc":
					return new OdbcParameter("@" + fieldName, val);
				case "System.Data.OleDb":
					return new OleDbParameter("@" + fieldName, val);
			}
			return new SqlParameter("@" + fieldName, val);
		}
	}
}
